package com.yunfeng.common.dao;

import java.util.List;

import javax.persistence.QueryHint;

import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.jpa.repository.QueryHints;

import com.yunfeng.common.entity.impl.Module;

public interface ModuleDAO extends JpaRepository<Module, Long> {
	Page<Module> findByParentId(Long parentId, Pageable pageable);

	Page<Module> findByParentIdAndNameContaining(Long parentId, String name,
			Pageable pageable);

	@QueryHints(value = {
			@QueryHint(name = "org.hibernate.cacheable", value = "true"),
			@QueryHint(name = "org.hibernate.cacheRegion", value = "com.yunfeng.common.entity.impl.Module") })
	@Query("from Module m order by m.priority ASC")
	List<Module> findAllWithCache();

	/**
	 * 根据sn，查找Module 描述
	 * 
	 * @param sn
	 * @return
	 */
	List<Module> findBySn(String sn);
}
